<section class="content-wrapper">
	<div class="content-container container">
		<div class="col-1-layout">
            <?php if($this->data['count'] > 0): ?>
                <ul class="shopping-cart-table">
    				<li class="item-image">
    					<?php echo $this->translate('image'); ?>
    				</li>
    				<li class="item-name">
    					<?php echo $this->translate('product name'); ?>
    				</li>
                    <li class="item-quantity">
    					<?php echo $this->translate('quantity'); ?>
    				</li>
                    <li class="item-price">
                        <?php echo $this->translate('price'); ?>
                    </li>
                    <li class="item-price-total">
                        <?php echo $this->translate('price total'); ?>
                    </li>
                    <li class="item-remove">
                        <?php echo $this->translate('remove'); ?>
                    </li>
    			</ul>
            <form id="form" action="" method="post">
                <?php foreach($this->data['items'] as $item): ?>
                <hr />
        			<ul class="shopping-cart-table">
        				<li class="item-image">
        					<div class="img-box">
                                <img src="<?php echo $item['image']; ?>" title="<?php echo $item['name']; ?>" alt="<?php echo $item['name']; ?>" />
                            </div>
        				</li>
        				<li class="item-name">
        					<a href="<?php echo $this->url(array('controller' => 'product', 'action' => 'detail', 'product_id' => $item['id']), null, true); ?>" title="<?php echo $item['name']; ?>">
                                <?php echo $item['name']; ?>
                            </a>
        				</li>
                        <li class="item-quantity">
        					<input id="quantity" maxlength="3" type="text" name="quantity[<?php echo $item['id']; ?>]" value="<?php echo $item['quantity']; ?>" />
        				</li>
                        <li class="item-price">
                            <strong>x</strong> <?php echo number_format($item['price'], 0, null, "."); ?><?php echo $this->translate('currency'); ?>
                        </li>
                        <li class="item-price-total">
                            <?php echo number_format($item['total'], 0, null, "."); ?><?php echo $this->translate('currency'); ?>
                        </li>
                        <li class="item-remove">
                            <a id="removeItem" href="javascript:removeItem('<?php echo $item['id']; ?>')">
                                <img alt="Remove" title="Remove" src="<?php echo $this->templateURL; ?>/images/delete_item_btn.png" />
                            </a>
                        </li>
        			</ul>
                <?php endforeach; ?>
            </form>
            <?php else: ?>
            <span class="cart-no-item"><?php echo $this->translate('no item'); ?></span>
            <?php endif; ?>
			<div class="update-shopping-cart">
                <button id="updateCart" class="colors-btn">
                    <?php echo $this->translate('update cart'); ?>
                </button>
            </div>
			<div class="shopping-cart-collaterals">
				<div class="cart-box">
					<div class="box-title">
                        <?php echo $this->translate('discount code'); ?>
                    </div>
					<div class="box-content">
                        <p>
                            <?php echo $this->translate('Enter your coupon code if you have one.'); ?>
                        </p>
                        <?php if($this->haveCoupon): ?>
                        <input type="text" readonly="" disabled="" id="coupon" maxlength="50" name="coupon" value="<?php echo $this->coupon['voucher_code']; ?>" />
                        <?php else: ?>
                        <input type="text" id="coupon" maxlength="50" name="coupon" value="" />
                        <?php endif; ?>
                    </div>
                    <?php if(!$this->haveCoupon): ?>
    					<button id="applyCoupon" class="colors-btn" title="<?php echo $this->translate('apply'); ?>">
                            <?php echo $this->translate('apply'); ?>
                        </button>
                    <?php else: ?>
                        <button id="removeCoupon" class="colors-btn" title="<?php echo $this->translate('remove coupon'); ?>">
                            <?php echo $this->translate('remove coupon'); ?>
                        </button>
                        <div class="clearfix"></div>
                        <blockquote class="coupon-description">
                            <?php echo $this->coupon['description']; ?><br />
                            <?php
                                echo $this->translate('discount') . ": ";
                                if($this->coupon['type']){
                                    echo $this->coupon['value'] . $this->translate('percent symbol');
                                }else{
                                    echo number_format($this->coupon['value'], 0, null, ".") . $this->translate('currency');
                                }
                            ?><br />
                            <?php echo $this->translate('apply for'); ?>
                            <?php 
                                if($this->coupon['order_value'] > 0){
                                    echo $this->translate('order value over') . number_format($this->coupon['order_value'], 0, null, ".") . $this->translate('currency');
                                }else{
                                    echo $this->translate('all orders');
                                }
                            ?>
                        </blockquote>
                    <?php endif; ?>
				</div>
				<div class="cart-box">
					<div class="box-title"><?php echo $this->translate('shipping method'); ?></div>
					<div class="box-content">
						<ul>
							<li>
								<label>Country<em>*</em></label>
								<select><option>United States</option></select>
							</li>
							<li>
								<label>State/Province</label>
								<select><option>Please select region, state or province</option></select>
							</li>
							<li>
								<label>Zip/Postal Code</label>
								<input type="text" />
							</li>
						</ul>
					</div>
					<button class="colors-btn" title="Get a Quote">Get a Quote</button>
				</div>
			</div>
			<div class="shopping-cart-totals">
				<div class="subtotal-row">
                    <div class="left">
                        <?php echo $this->translate('total'); ?>
                    </div>
                    <div class="right">
                        <?php echo number_format($this->data['subtotal'], 0, null, "."); ?><?php echo $this->translate('currency'); ?>
                    </div>
                </div>
                <?php if($this->haveCoupon): ?>
                <div class="subtotal-row">
                    <div class="left">
                        <?php echo $this->translate('discount'); ?>
                    </div>
                    <div class="right">
                        <?php echo number_format($this->coupon['discount_price'], 0, null, "."); ?><?php echo $this->translate('currency'); ?>
                    </div>
                </div>
                <?php endif; ?>
				<div class="grand-row">
                    <div class="left">
                        <?php echo $this->translate('grand total'); ?>
                    </div>
                    <div class="right">
                        <?php echo number_format($this->data['total'], 0, null, "."); ?><?php echo $this->translate('currency'); ?>
                    </div>
                </div>
				<ul class="checkout-types">
					<li>
                        <form method="post" action="<?php echo $this->url(array(), 'checkout', true); ?>">
                        <?php foreach($this->data['items'] as $item): ?>
                        <input type="hidden" name="items[<?php echo $item['id']; ?>][name]" value="<?php echo $item['name']; ?>" />
                        <input type="hidden" name="items[<?php echo $item['id']; ?>][quantity]" value="<?php echo $item['quantity']; ?>" />
                        <input type="hidden" name="items[<?php echo $item['id']; ?>][price]" value="<?php echo $item['price']; ?>" />
                        <input type="hidden" name="items[<?php echo $item['id']; ?>][total]" value="<?php echo $item['total']; ?>" />
                        <?php endforeach; ?>
                        <?php if($this->haveCoupon): ?>
                        <input type="hidden" name="discount_price" value="<?php echo $this->coupon['discount_price']; ?>" />
                        <input type="hidden" name="voucher_code" value="<?php echo $this->coupon['voucher_code']; ?>" />
                        <?php endif; ?>
                        <input type="hidden" name="total" value="<?php echo $this->data['total']; ?>" />
                        <input type="hidden" name="subtotal" value="<?php echo $this->data['subtotal']; ?>" />
                        <button type="submit" class="colors-btn" title="<?php echo $this->translate('checkout'); ?>">
                            <?php echo $this->translate('checkout'); ?>
                        </button>
                        </form>
                    </li>
				</ul>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="news-letter-container">
			<div class="free-shipping-block">
				<h1>ENJOY FREE SHIPPING</h1>
				<p>on all orders as our holiday gift for you!</p>
			</div>
			<div class="news-letter-block">
				<h2>SIGN UP FOR OUR NEWSLETTER</h2>
				<input type="text" value="Enter email address" title="" />
				<input class="submit-btn" type="submit" value="Submit" title="Submit" />
			</div>
		</div>	
	</div>
</section>
<script>
$(document).ready(function(){
    $(".banner-wrapper").remove();
    
    $("input[id='quantity']").priceFormat({
        prefix: '',
        clearPrefix: true,
        thousandsSeparator: '.',
        centsLimit: 0,
        limit: 3
    });
    
    $("#removeItem").click(function(){
        $(this).parent("li.item-remove").parent('ul.shopping-cart-table').remove();
    });
    
    $("#updateCart").click(function(){
        $("#form").submit();
    });
    
    $("#applyCoupon").click(function(){
        var coupon = $("#coupon").val();
        
        if(coupon.length > 0){
            $.ajax({
                type: "post",
                url: "<?php echo $this->url(array(), 'voucher_check', true) ?>",
                data: {'coupon': coupon},
                beforeSend: function( result ) {
                    var html = '<img id="loading" src="<?php echo $this->templateURL; ?>/images/loading.gif" />';
                    $("#applyCoupon").after(html);
                },
                success: function(result){
                    if(result == 1){
                        location.reload();
                    }else{
                        alert("<?php echo $this->translate('invalid coupon') ?>");
                        $("#coupon").val('');
                    }
                    $("img#loading").remove();
                }
            });
        }else{
            alert('<?php echo $this->translate('please enter coupon'); ?>')
        }
    });
    
    $("#removeCoupon").click(function(){
        var coupon = $("#coupon").val();
        
        $.ajax({
            type: "post",
            url: "<?php echo $this->url(array(), 'voucher_remove', true) ?>",
            data: {'coupon': coupon},
            beforeSend: function( result ) {
                var html = '<img id="loading" src="<?php echo $this->templateURL; ?>/images/loading.gif" />';
                $("#removeCoupon").after(html);
            },
            success: function(result){
                location.reload();
                $("img#loading").remove();
            }
        });
    });
});
</script>